package org.apache.flink.client.cluster;

import java.util.concurrent.CompletableFuture;

import org.apache.flink.api.common.ConsumerID;
import org.apache.flink.api.common.ConsumingStatus;
import org.apache.flink.api.common.ResourceStatus;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.allocation.ResourceAllocationStatistics;
import org.apache.flink.runtime.messages.Acknowledge;

/**
 * Encapsulates the functionality necessary to submit a program to a remote cluster.
 *
 * @param <T> type of the cluster id
 */
public interface ClusterClient<T> extends AutoCloseable {

    /**
     * Returns the cluster id identifying the cluster to which the client is connected.
     *
     * @return cluster id of the connected cluster
     */
    T getClusterId();

    /**
     * Return the Flink configuration object.
     *
     * @return The Flink configuration object
     */
    Configuration getFlinkConfiguration();


    @Override
    void close();
    
    /** Shut down the cluster that this client communicate with. */
    void shutDownCluster();

    /** Returns an URL (as a string) to the cluster web interface. */
    String getWebInterfaceURL();

    /** Requests the {@link ConsumingStatus} of the job with the given {@link ConsumerID}. */
    CompletableFuture<ConsumingStatus> getConsumingStatus(ConsumerID consumerId);

    // 资源消费状态
    CompletableFuture<ResourceStatus> getResourceStatus();
    
    // 资源分配统计
    CompletableFuture<ResourceAllocationStatistics> getResourceAllocationStatistics();

    /**
     * Cancels a consumption identified by the consumer id.
     * 支持多个consumer公用集群
     *
     * @param consumerId the job id
     */
    CompletableFuture<Acknowledge> cancel(ConsumerID consumerId);

}
